// BaseFragment.kt
package com.ityun.ogapp.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.jaeger.library.StatusBarUtil

abstract class BaseFragment<T : ViewBinding> : Fragment() {

    protected lateinit var mBinding: T

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mBinding = createViewBinding(inflater, container)
        return mBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // 设置状态栏透明（沉浸式）
        activity?.let { StatusBarUtil.setTransparent(it) }
        // 设置状态栏字体颜色为深色
        view.post {
            activity?.let { StatusBarUtil.setDarkMode(it) }
        }
        initViews()
        initData()
        subscribe()
    }

    // 子类需要实现此方法来创建对应的ViewBinding实例
    protected abstract fun createViewBinding(inflater: LayoutInflater, container: ViewGroup?): T

    // 初始化视图组件，子类可重写
    protected open fun initViews() {}

    // 初始化数据，子类可重写
    protected open fun initData() {}

    protected open fun subscribe() {}
}
